package com.deliveryservicesystem.model;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * File Name: Route.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.model.newpackage
 * Author: Lance
 * Date: Jun 24, 2012
 * Editor:
 */
@Entity
@Table(name = "ROUTE")
@XmlRootElement
@NamedQueries(
{
    @NamedQuery(name = "Route.findAll", query = "SELECT r FROM Route r"),
    @NamedQuery(name = "Route.findByRouteNo", query = "SELECT r FROM Route r WHERE r.routeNo = :routeNo"),
    @NamedQuery(name = "Route.findByMainRoute", query = "SELECT r FROM Route r WHERE r.mainRoute = :mainRoute")
})
public class Route implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "SEQ_ROUTE_NO", sequenceName = "SEQ_ROUTE_NO")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_ROUTE_NO")
    @Basic(optional = false)
    @Column(name = "ROUTE_NO")
    private Integer routeNo;
    @Column(name = "MAIN_ROUTE")
    private String mainRoute;
    @JoinColumn(name = "DELIVERY_NO", referencedColumnName = "DELIVERY_NO")
    @ManyToOne
    private Delivery deliveryNo;

    public Route()
    {
    }

    public Route(Integer routeNo)
    {
        this.routeNo = routeNo;
    }

    public Integer getRouteNo()
    {
        return routeNo;
    }

    public void setRouteNo(Integer routeNo)
    {
        this.routeNo = routeNo;
    }

    public String getMainRoute()
    {
        return mainRoute;
    }

    public void setMainRoute(String mainRoute)
    {
        this.mainRoute = mainRoute;
    }

    public Delivery getDeliveryNo()
    {
        return deliveryNo;
    }

    public void setDeliveryNo(Delivery deliveryNo)
    {
        this.deliveryNo = deliveryNo;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (routeNo != null ? routeNo.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Route))
        {
            return false;
        }
        Route other = (Route) object;
        if ((this.routeNo == null && other.routeNo != null) || (this.routeNo != null && !this.routeNo.equals(other.routeNo)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "Boute Number: " + routeNo
                + "\nMain Route: " + mainRoute
                + "\nDelivery Number: " + deliveryNo.getDeliveryNo();
    }
}
